# coding: utf-8
import datetime
import pytz


def Minute(times):
    hour, min = times.tm_hour, times.tm_min
    if hour == 8:
        hour = 9
        min = 0
    elif hour == 13 and min < 30:
        min = 30
    elif hour == 20:
        hour = 21
        min = 0
    datetime1 = datetime.datetime(times.tm_year, times.tm_mon, times.tm_mday, hour, min, 0)
    return datetime1


def Minute5(times):
    day = 0
    hour, min = times.tm_hour, times.tm_min

    if hour == 9 and min == 0:
        min = 5
    elif hour == 13 and min <= 30:
        min = 35
    else:
        suf = 5 if (min % 5 > 0) else 0
        min = min / 5 * 5 + suf
        if min == 60:
            if hour == 23:
                hour, min = 0, 0
                day += 1
            else:
                min = 0
                hour += 1
    datetime_5 = datetime.datetime(times.tm_year, times.tm_mon, times.tm_mday, hour, min, 0)
    if day > 0:
        datetime_5 = datetime_5 + datetime.timedelta(1)
    return datetime_5


def Minute15(times):
    day = 0
    hour, min = times.tm_hour, times.tm_min
    if hour == 9 and min == 0:
        min = 15
    elif hour == 13 and min <= 30:
        min = 45
    else:
        suf = 15 if min % 15 > 0 else 0
        min = min / 15 * 15 + suf
        if min == 60:
            if hour == 23:
                hour, min = 0, 0
                day += 1
            else:
                min = 0
                hour += 1
    datetime_15 = datetime.datetime(times.tm_year, times.tm_mon, times.tm_mday, hour, min, 0)
    if day > 0:
        datetime_15 = datetime_15 + datetime.timedelta(1)
    return datetime_15


def Minute60(dateTimes, symbol):
    list = []
    tz = pytz.timezone(pytz.country_timezones('cn')[0])
    for times in dateTimes:
        day = 0
        hour, min = times.hour, times.minute
        alpha = filter(str.isalpha, symbol).upper()
        if alpha == "RB" or alpha == "BU":
            # 9.
            if hour == 9 and min > 0:
                min = 0
            elif hour == 10 and min <= 0:
                hour = 9
                min = 0
            # 10.
            elif hour == 10 and min > 0:
                min = 0
            elif hour == 11 and min <= 15:
                hour = 10
                min = 0
            # 11.15
            elif hour == 11 and min > 15:
                min = 15
            elif 11 < hour < 14:
                hour = 11
                min = 15
            elif hour == 14 and min <= 15:
                hour = 11
                min = 15
            # 14.15
            elif hour == 14 and min > 15:
                min = 15
            elif hour == 15:
                hour = 14
                min = 15
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                min = 0
            # 23.0
            elif 23 <= hour:
                hour = 23
                min = 0
            elif 0 <= hour < 9:
                day -= 1
                hour = 0
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        elif alpha == 'IF' or alpha == 'TF':
            # 9.30
            if hour == 9 and min < 30:
                min = 30
            elif hour < 9:
                hour = 9
                min = 15
            # 10.30
            elif hour == 9 and min >= 30:
                hour = 10
                min = 30
            elif hour == 10 and min < 30:
                hour = 10
                min = 30
            # 11.30
            elif hour == 10 and min >= 30:
                hour = 11
                min = 30
            elif hour == 11:
                min = 30
            # 13.
            elif hour == 13:
                hour = 14
                min = 0
            # 14.
            elif hour == 14:
                hour = 15
                min = 0
            elif hour >= 15:
                hour = 15
                min = 15
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        else:
            # 9.30
            if hour == 9 and min > 30:
                min = 30
            elif hour == 10 and min <= 45:
                hour = 9
                min = 30
            # 10.45
            elif hour == 10 and min > 45:
                min = 45
            elif hour == 11:
                hour = 10
                min = 45
            elif hour == 13 and min <= 45:
                hour = 10
                min = 45
            # 13.45
            elif hour == 13 and min > 45:
                min = 45
            elif hour == 14 and min <= 45:
                hour = 13
                min = 45
            # 14.45
            elif hour == 14 and min > 45:
                min = 45
            elif hour == 15:
                hour = 14
                min = 45
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                min = 0
            # 23.0
            elif 23 <= hour:
                hour = 23
                min = 0
            elif 0 <= hour < 9:
                day -= 1
                hour = 23
                min = 0
            elif hour == 9 and min <= 30:
                day -= 1
                hour = 23
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            if day < 0:
                if datetime_60.weekday() == 0:  # mon
                    datetime_60 = datetime_60 - datetime.timedelta(3)
                else:
                    datetime_60 = datetime_60 - datetime.timedelta(1)
            list.append(datetime_60)
    return list


def Minute30New(dateTimes, symbol):
    list = []
    tz = pytz.timezone(pytz.country_timezones('cn')[0])
    for times in dateTimes:
        day = 0
        times = times + datetime.timedelta(hours=0)
        hour, min = times.hour, times.minute
        alpha = filter(str.isalpha, symbol).upper()
        if alpha == "RB" or alpha == "BU" or alpha == 'NI':
            # 9.
            if hour == 0 and min > 30:
                hour = 0
                min = 30
            elif hour < 9:
                hour = 0
                min = 30
            elif hour == 10 and min < 45:
                min = 0
            # 10.15~10.30中场休息
            elif ((hour == 10 and min >= 45) or (hour >= 11 and hour <= 15)):
                if hour == 11 and min >= 30:
                    hour = 11
                    min = 15
                elif hour == 13 and min < 45:
                    hour = 11
                    min = 15
                elif hour == 15 and min >= 0:
                    hour = 14
                    min = 45
                else:
                    if min / 45 > 0:
                        min = 45
                    elif min / 15 > 0 and min / 45 == 0:
                        min = 15
                    elif min / 15 == 0:
                        if hour == 13:
                            hour = 11
                            min = 15
                        else:
                            hour -= 1
                            min = 45
            else:
                min = min / 30 * 30
            datetime_30 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_30 = tz.localize(datetime_30)
            list.append(datetime_30)
        elif alpha == 'IF' or alpha == 'IC' or alpha == 'IH':
            if hour == 9 and min < 30:
                min = 30
            elif hour == 11 and min >= 30:
                min = 0
            elif hour == 12 and min < 59:
                hour = 11
                min = 0
            elif hour == 12 and min == 59:
                hour = 13
                min = 0
            elif hour == 15 and min == 0:
                hour = 14
                min = 30
            else:
                min = min / 30 * 30
            datetime_30 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_30 = tz.localize(datetime_30)
            list.append(datetime_30)
        elif alpha == 'TF' or alpha == 'T':
            if hour == 9 and min < 15:
                min = 15
            elif (hour == 11 and min >= 30) and hour < 13:
                hour = 11
                min = 0
            elif hour == 15 and min == 15:
                hour = 14
                min = 45
            else:
                if min / 45 > 0:
                    min = 45
                elif min / 15 > 0 and min / 45 == 0:
                    min = 15
                elif min / 15 == 0:
                    if hour == 13:
                        hour = 11
                        min = 15
                    else:
                        hour = hour - 1
                        min = 45
            datetime_30 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_30 = tz.localize(datetime_30)
            list.append(datetime_30)
        elif alpha == 'RU':
            if hour == 23 and min == 0:
                hour = 22
                min = 30
            elif hour < 9:
                hour = 9
                min = 0
            elif hour == 10 and min < 45:
                min = 0
            # 10.15~10.30中场休息
            elif ((hour == 10 and min >= 45) or (hour >= 11 and hour <= 15)):
                if hour == 11 and min >= 30:
                    hour = 11
                    min = 15
                elif hour == 13 and min < 45:
                    hour = 11
                    min = 15
                elif hour == 15 and min >= 0:
                    hour = 14
                    min = 45
                else:
                    if min / 45 > 0:
                        min = 45
                    elif min / 15 > 0 and min / 45 == 0:
                        min = 15
                    elif min / 15 == 0:
                        if hour == 13:
                            hour = 11
                            min = 15
                        else:
                            hour -= 1
                            min = 45
            else:
                min = min / 30 * 30
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        else:
            if hour == 23 and min >= 30:
                min = 0
            elif hour < 9:
                day = -1
                hour = 23
                min = 0
            elif hour == 10 and min < 45:
                min = 0
            # 10.15~10.30中场休息
            elif ((hour == 10 and min >= 45) or (hour >= 11 and hour <= 15)):
                if hour == 11 and min >= 30:
                    hour = 11
                    min = 15
                elif hour == 13 and min < 45:
                    hour = 11
                    min = 15
                elif hour == 15 and min >= 0:
                    hour = 14
                    min = 45
                else:
                    if min / 45 > 0:
                        min = 45
                    elif min / 15 > 0 and min / 45 == 0:
                        min = 15
                    elif min / 15 == 0:
                        if hour == 13:
                            hour = 11
                            min = 15
                        else:
                            hour -= 1
                            min = 45
            else:
                min = min / 30 * 30
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            if day < 0:
                if datetime_60.weekday() == 0:  # mon
                    datetime_60 = datetime_60 - datetime.timedelta(3)
                else:
                    datetime_60 = datetime_60 - datetime.timedelta(1)
            list.append(datetime_60)
    return list


def Minute60New(dateTimes, symbol):
    list = []
    tz = pytz.timezone(pytz.country_timezones('cn')[0])
    for times in dateTimes:
        day = 0
        times = times + datetime.timedelta(hours=0)
        hour, min = times.hour, times.minute
        alpha = filter(str.isalpha, symbol).upper()
        if alpha == "RB" or alpha == "BU" or alpha == 'NI' or alpha == "WH" or alpha == "SF" or alpha == "HC" or alpha == "PP":
            # 9.
            if hour == 9 and min > 0:
                min = 0
            elif hour == 10 and min <= 0:
                hour = 9
                min = 0
            # 10.
            elif hour == 10 and min > 0:
                min = 0
            elif hour == 11 and min <= 15:
                hour = 10
                min = 0
            # 11.15
            elif hour == 11 and min > 15:
                min = 15
            elif 11 < hour < 14:
                hour = 11
                min = 15
            elif hour == 14 and min <= 15:
                hour = 11
                min = 15
            # 14.15
            elif hour == 14 and min > 15:
                min = 15
            elif hour == 15:
                hour = 14
                min = 15
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                min = 0
            # 23.0
            elif hour == 23:
                hour = 22
                min = 0
            elif 23 < hour:
                hour = 22
                min = 0
            elif hour == 8:
                hour = 9
                min = 0
            elif 0 <= hour < 8:
                day -= 1
                hour = 22
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        elif alpha == "RU":
            # 9.
            if hour == 9 and min > 0:
                min = 0
            elif hour == 10 and min <= 0:
                hour = 9
                min = 0
            # 10.
            elif hour == 10 and min > 0:
                min = 0
            elif hour == 11 and min <= 15:
                hour = 10
                min = 0
            # 11.15
            elif hour == 11 and min > 15:
                min = 15
            elif 11 < hour < 14:
                hour = 11
                min = 15
            elif hour == 14 and min <= 15:
                hour = 11
                min = 15
            # 14.15
            elif hour == 14 and min > 15:
                min = 15
            elif hour == 15:
                hour = 14
                min = 15
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                min = 0
            # 23.0
            elif hour == 23 and min == 0:
                hour = 22
                min = 0
            elif hour == 23 and min > 0:
                hour = 22
                min = 0
            elif 0 <= hour < 9:
                hour = 9
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        elif alpha == "AL" or alpha == "CU" or alpha == 'ZN' or alpha == "PB" or alpha == "SN":
            # 9.
            if hour == 9 and min > 0:
                min = 0
            elif hour == 10 and min <= 0:
                hour = 9
                min = 0
            # 10.
            elif hour == 10 and min > 0:
                min = 0
            elif hour == 11 and min <= 15:
                hour = 10
                min = 0
            # 11.15
            elif hour == 11 and min > 15:
                min = 15
            elif 11 < hour < 14:
                hour = 11
                min = 15
            elif hour == 14 and min <= 15:
                hour = 11
                min = 15
            # 14.15
            elif hour == 14 and min > 15:
                min = 15
            elif hour == 15:
                hour = 14
                min = 15
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                min = 0
            # 23.0
            elif 23 <= hour:
                hour = 23
                min = 0
            elif 0 <= hour < 9:
                hour = 0
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        elif alpha == "AU" or alpha == "AG":
            # 9.30
            if hour == 9 and min > 30:
                min = 30
            elif hour == 10 and min <= 45:
                hour = 9
                min = 30
            # 10.45
            elif hour == 10 and min > 45:
                min = 45
            elif hour == 11:
                hour = 10
                min = 45
            elif hour == 13 and min <= 45:
                hour = 10
                min = 45
            # 13.45
            elif hour == 13 and min > 45:
                min = 45
            elif hour == 14 and min <= 45:
                hour = 13
                min = 45
            # 14.45
            elif hour == 14 and min > 45:
                min = 45
            elif hour == 15:
                hour = 14
                min = 45
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                min = 0
            # 23.0
            elif 23 <= hour:
                hour = 23
                min = 0
            elif 0 <= hour < 1:
                hour = 0
                min = 0
            elif 1 <= hour < 2:
                hour = 1
                min = 0
            elif 2 <= hour < 9:
                hour = 2
                min = 0
            elif hour == 9 and min <= 30:
                hour = 2
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        elif alpha == "L":
            # 9.
            if hour == 9 and min > 0:
                min = 0
            elif hour == 10 and min <= 0:
                hour = 9
                min = 0
            # 10.
            elif hour == 10 and min > 0:
                min = 0
            elif hour == 11 and min <= 15:
                hour = 10
                min = 0
            # 11.15
            elif hour == 11 and min > 15:
                min = 15
            elif 11 < hour < 14:
                hour = 11
                min = 15
            elif hour == 14 and min <= 15:
                hour = 11
                min = 15
            # 14.15
            elif hour == 14 and min > 15:
                min = 15
            elif hour == 15:
                hour = 14
                min = 15
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        elif alpha == 'IF' or alpha == 'IC' or alpha == 'IH':
            # 9.30
            if hour == 9 and min < 30:
                hour = 10
                min = 30
            # 10.30
            elif hour == 9 and min >= 30:
                hour = 10
                min = 30
            elif hour == 10 and min < 30:
                hour = 10
                min = 30
            # 11.30
            elif hour == 10 and min >= 30:
                hour = 11
                min = 30
            elif hour == 11:
                min = 30
            # 13.
            elif hour == 13:
                hour = 14
                min = 0
            # 14.
            elif hour == 14:
                hour = 15
                min = 0
            elif hour == 15 and min <= 15:
                hour = 15
                min = 0
            elif hour == 15 and min < 20:
                hour = 15
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        elif alpha == 'TF' or alpha == 'T':
            # 9.15
            if hour == 9:
                min = 15
            elif hour < 9:
                hour = 9
                min = 15
            elif hour == 10 and min < 15:
                hour = 9
                min = 15
            # 10.15
            elif hour == 10 and min >= 15:
                hour = 10
                min = 15
            elif hour == 11 and min < 15:
                hour = 10
                min = 15
            # 11.15
            elif hour == 11 and min >= 15:
                hour = 11
                min = 15
            elif hour == 13 and min < 45:
                hour = 11
                min = 15
            # 13.45
            elif hour == 13 and min >= 45:
                hour = 13
                min = 45
            elif hour == 14 and min < 45:
                hour = 13
                min = 45
            # 14.45
            elif hour == 14 and min >= 45:
                hour = 14
                min = 45
            elif hour == 15:
                hour = 14
                min = 45
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            list.append(datetime_60)
        else:
            # 9.30
            if hour == 9 and min > 30:
                min = 30
            elif hour == 10 and min <= 45:
                hour = 9
                min = 30
            # 10.45
            elif hour == 10 and min > 45:
                min = 45
            elif hour == 11:
                hour = 10
                min = 45
            elif hour == 13 and min <= 45:
                hour = 10
                min = 45
            # 13.45
            elif hour == 13 and min > 45:
                min = 45
            elif hour == 14 and min <= 45:
                hour = 13
                min = 45
            # 14.45
            elif hour == 14 and min > 45:
                min = 45
            elif hour == 15:
                hour = 14
                min = 45
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                min = 0
            # 23.0
            elif 23 <= hour:
                hour = 23
                min = 0
            elif 0 <= hour < 9:
                day -= 1
                hour = 23
                min = 0
            elif hour == 9 and min <= 30:
                day -= 1
                hour = 23
                min = 0
            datetime_60 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_60 = tz.localize(datetime_60)
            if day < 0:
                if datetime_60.weekday() == 0:  # mon
                    datetime_60 = datetime_60 - datetime.timedelta(3)
                else:
                    datetime_60 = datetime_60 - datetime.timedelta(1)
            list.append(datetime_60)
    return list


def Minute120New(dateTimes, symbol):
    list = []
    tz = pytz.timezone(pytz.country_timezones('cn')[0])
    for times in dateTimes:
        day = 0
        times = times + datetime.timedelta(hours=0)
        hour, min = times.hour, times.minute
        alpha = filter(str.isalpha, symbol).upper()
        if alpha == "RB" or alpha == "BU" or alpha == 'NI'or alpha == "WH" or alpha == "SF" or alpha == "HC" or alpha == "PP":
            # 9.
            if hour == 9 and min > 0:
                min = 0
            elif hour == 10:
                hour = 9
                min = 0
            elif hour == 11 and min <= 15:
                hour = 9
                min = 0
            elif hour == 11 and min > 15:
                min = 15
            elif 11 < hour < 14:
                hour = 11
                min = 15
            elif hour == 14 and min <= 15:
                hour = 11
                min = 15
            # 14.15
            elif hour == 14 and min > 15:
                hour = 11
                min = 15
            elif hour == 15:
                hour = 11
                min = 15
            elif hour == 15 and min < 20:
                hour = 11
                min = 15
            elif 15 < hour < 20:
                hour = 21
                min = 0
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                hour = 21
                min = 0
            # 23.0
            elif 23 <= hour:
                hour = 23
                min = 0
            elif 0 <= hour < 9:
                day = -1
                hour = 23
                min = 0
            datetime_120 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_120 = tz.localize(datetime_120)
            if day < 0:
                if datetime_120.weekday() == 0:  # mon
                    datetime_120 = datetime_120 - datetime.timedelta(3)
                else:
                    datetime_120 = datetime_120 - datetime.timedelta(1)
            list.append(datetime_120)
        elif alpha == 'RU':
            # 9.
            if hour == 9 and min > 0:
                min = 0
            elif hour == 10:
                hour = 9
                min = 0
            elif hour == 11 and min <= 15:
                hour = 9
                min = 0
            elif hour == 11 and min > 15:
                min = 15
            elif 11 < hour < 14:
                hour = 11
                min = 15
            elif hour == 14 and min <= 15:
                hour = 11
                min = 15
            # 14.15
            elif hour == 14 and min > 15:
                hour = 11
                min = 15
            elif hour == 15:
                hour = 11
                min = 15
            elif hour == 15 and min < 20:
                hour = 11
                min = 15
            elif 15 < hour < 20:
                hour = 21
                min = 0
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif 21 <= hour < 22:
                min = 0
            # 22.0
            elif 22 <= hour < 23:
                hour = 21
                min = 0
            # 23.0
            elif 23 <= hour:
                hour = 21
                min = 0
            elif 0 <= hour < 9:
                hour = 9
                min = 0
            datetime_120 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_120 = tz.localize(datetime_120)
            if day < 0:
                if datetime_120.weekday() == 0:  # mon
                    datetime_120 = datetime_120 - datetime.timedelta(3)
                else:
                    datetime_120 = datetime_120 - datetime.timedelta(1)
            list.append(datetime_120)
        elif alpha == 'IF' or alpha == 'IC' or alpha == 'IH':
            if 9 <= hour <= 11:
                hour = 9
                min = 30
            # 11.30
            elif hour == 12:
                hour = 13
                min = 0
            # 13.
            elif hour == 13:
                min = 0
            # 14.
            elif hour == 14:
                hour = 13
                min = 0
            elif hour == 15 and min <= 15:
                hour = 13
                min = 0
            elif hour == 15 and min < 59:
                hour = 13
                min = 0
            datetime_120 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_120 = tz.localize(datetime_120)
            list.append(datetime_120)
        elif alpha == 'TF' or alpha == 'T':
            # 9.15
            if hour == 9:
                min = 15
            elif hour < 9:
                hour = 9
                min = 15
            elif hour == 10:
                hour = 9
                min = 15
            elif hour == 11 and min < 15:
                hour = 9
                min = 15
            # 11.15
            elif hour == 11 and min >= 15:
                min = 15
            elif hour == 12:
                hour = 11
                min = 15
            elif hour == 13:
                hour = 11
                min = 15
            elif hour == 14:
                hour = 11
                min = 15
            elif hour == 15:
                hour = 11
                min = 15
            datetime_120 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_120 = tz.localize(datetime_120)
            list.append(datetime_120)
        else:
            if hour == 10 and min > 45:
                min = 45
            elif hour == 11:
                hour = 10
                min = 45
            elif hour == 13:
                hour = 10
                min = 45
            elif hour == 14 or hour == 15:
                hour = 10
                min = 45
            # 14.45
            elif hour == 15 and min < 20:
                hour = 10
                min = 45
            # 21.0
            elif hour == 20:
                hour = 21
                min = 0
            elif hour == 21:
                hour = 21
                min = 0
            # 22.0
            elif hour == 22:
                hour = 21
                min = 0
            # 23.0
            elif hour == 23:
                hour = 23
                min = 0
            elif 0 <= hour < 10:
                day = -1
                hour = 23
                min = 0
            elif hour == 10 and min <= 45:
                day = -1
                hour = 23
                min = 0
            datetime_120 = datetime.datetime(times.year, times.month, times.day, hour, min, 0)
            datetime_120 = tz.localize(datetime_120)
            if day < 0:
                if datetime_120.weekday() == 0:  # mon
                    datetime_120 = datetime_120 - datetime.timedelta(3)
                else:
                    datetime_120 = datetime_120 - datetime.timedelta(1)
            list.append(datetime_120)
    return list


def Minute24(times):
    day = 0
    hour, min = times.tm_hour, times.tm_min
    datetime_24 = datetime.datetime(times.tm_year, times.tm_mon, times.tm_mday, 0, 0, 0)
    if hour >= 21:
        if datetime_24.weekday() == 4:  # fri
            datetime_24 = datetime_24 + datetime.timedelta(3)
        else:
            datetime_24 = datetime_24 + datetime.timedelta(1)
    else:
        datetime_24 = datetime.datetime(times.tm_year, times.tm_mon, times.tm_mday, 0, 0, 0)
    return datetime_24


def dfMinute5(dateTimes):
    list = []
    for dateTime in dateTimes:
        day = 0
        hour, min = dateTime.hour, dateTime.minute

        if hour == 9 and min == 0:
            min = 5
        elif hour == 13 and min <= 30:
            min = 35
        else:
            suf = 5 if (min % 5 > 0) else 0
            min = min / 5 * 5 + suf
            if min == 60:
                if hour == 23:
                    hour, min = 0, 0
                    day += 1
                else:
                    min = 0
                    hour += 1
        datetime_5 = datetime.datetime(dateTime.year, dateTime.month, dateTime.day, hour, min, 0)
        if day > 0:
            datetime_5 = datetime_5 + datetime.timedelta(1)
        list.append(datetime_5)
    return list


def dfMinute60(dateTimes):
    list = []
    for dateTime in dateTimes:
        day = 0
        hour, min = dateTime.hour, dateTime.minute
        # 9.30
        if hour == 9 and min > 30:
            min = 30
        elif hour == 10 and min <= 45:
            hour = 9
            min = 30
        # 10.45
        elif hour == 10 and min > 45:
            min = 45
        elif hour == 11:
            hour = 10
            min = 45
        elif hour == 12:
            hour = 10
            min = 45
        elif hour == 13 and min <= 45:
            hour = 10
            min = 45
        # 13.45
        elif hour == 13 and min > 45:
            min = 45
        elif hour == 14 and min <= 45:
            hour = 13
            min = 45
        # 14.45
        elif hour == 14 and min > 45:
            min = 45
        elif hour == 15:
            hour = 14
            min = 45
        # 21.0
        elif 21 <= hour < 22:
            min = 0
        # 22.0
        elif 22 <= hour < 23:
            min = 0
        # 23.0
        elif 23 <= hour:
            hour = 23
            min = 0
        elif 0 <= hour < 9:
            day -= 1
            hour = 23
            min = 0
        elif hour == 9 and min <= 30:
            day -= 1
            hour = 23
            min = 0
        datetime_60 = datetime.datetime(dateTime.year, dateTime.month, dateTime.day, hour, min, 0)
        if day < 0:
            if datetime_60.weekday() == 0:  # mon
                datetime_60 = datetime_60 - datetime.timedelta(3)
            else:
                datetime_60 = datetime_60 - datetime.timedelta(1)
        list.append(datetime_60)
    return list


def Day(dateTimes):
    list = []
    tz = pytz.timezone(pytz.country_timezones('cn')[0])
    for times in dateTimes:
        day = 0
        hour, min = times.hour, times.minute
        # 21.0
        if hour > 15:
            day += 1
        datetime_60 = datetime.datetime(times.year, times.month, times.day, 0, 0, 0)
        datetime_60 = tz.localize(datetime_60)
        if day > 0:
            if datetime_60.weekday() == 4:  # mon
                datetime_60 = datetime_60 + datetime.timedelta(3)
            else:
                datetime_60 = datetime_60 + datetime.timedelta(1)
        list.append(datetime_60)
    return list

# min = 15
# hour = 9
# hour, min = Minute5(hour, min)
# print(hour, min)
# print(Minute15(hour, min))
# a = range(6)
# print(Minute60(hour, min))
# day = 23
# hour = 8
# min = 29
# print(Minute60(day, hour, min))

# tz = pytz.timezone(pytz.country_timezones('cn')[0])
# times = time.strptime('2015-11-24 142531', '%Y-%m-%d %H%M%S')
# datetime_1 = datetime.datetime(times.tm_year, times.tm_mon, times.tm_mday, times.tm_hour, times.tm_min,
#                                0)
# datetime_5 = Minute5(times)
# print(datetime_5)
